package personal.xjl._23java1studentdemo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import personal.xjl._23java1studentdemo.model.Course;
import personal.xjl._23java1studentdemo.model.Teacher;
import personal.xjl._23java1studentdemo.service.CourseService;

import java.util.List;

@Controller
@RequestMapping("/Course")
public class CourseController {
    @Autowired
    CourseService courseService;
    @RequestMapping("list")
    public String list(Model model) {
        List<Course> courses=courseService.findAll();
        model.addAttribute("courses", courses);
        return "listCourses";
    }
    //分页显示
    @RequestMapping("list/{currPage}/{pageSize}")
    public String list(Model model, @PathVariable("currPage") int currPage, @PathVariable("pageSize") int pageSize) {
        if (currPage < 1) currPage = 1;
        if (pageSize < 1) pageSize = 5;
        List<Course> courses = courseService.findByPage(currPage,pageSize);
        model.addAttribute("courses",courses);
        return "listCourses";
    }
}
